package admin

import (
	"e_mall_server/models"
	"e_mall_server/service"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"strconv"
)

/**
 * @Author: zhaobin
 * @Description TODO
 * @Date: 2022-05-12 9:56
 */

// UpdateSetting 修改商城设置信息接口
func UpdateSetting(c *gin.Context) {
	setting := models.Setting{}
	if err := c.ShouldBind(&setting); err != nil {
		zap.L().Error("UpdateSetting with invalid param", zap.Error(err))
		ResponseError(c, "请求参数错误")
		return
	}
	zap.L().Debug("setting数据", zap.Any("value", setting))
	// 业务逻辑处理
	if count := service.UpdateSetting(&setting); count > 0 {
		// 创建成功返回响应
		ResponseSuccess(c, nil)
		return
	}
	ResponseError(c, "修改商城设置失败 请重试")
}

// GetSettingDetailById 通过id查询商城设置信息
func GetSettingDetailById(c *gin.Context) {
	idStr := c.Param("id")
	id, err := strconv.ParseInt(idStr, 10, 64)
	if err != nil {
		zap.L().Error("GetSettingDetailById with invalid param", zap.Error(err))
		ResponseError(c, "请求参数错误")
	}
	Setting, err := service.GetSettingDetailById(id)
	if err != nil {
		zap.L().Error("service.GetSettingDetailById(id) failed", zap.Error(err))
		ResponseError(c, "获取管理员信息错误")
		return
	}
	ResponseSuccess(c, Setting)
}
